package servlet;

import util.Linksql;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;

public class Inform extends HttpServlet {
    Connection con=null;
   PreparedStatement pre=null;
   String sql="insert into message (pid,content,time) values(?,?,?)";
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        java.util.Date d=new Date();
        Timestamp date=new Timestamp(d.getTime());
        request.setCharacterEncoding("UTF8");
        con= Linksql.getConnection();
        try {
            pre=con.prepareStatement(sql);
            pre.setString(1,request.getParameter("id"));
            pre.setString(2,request.getParameter("text"));
            pre.setTimestamp(3,date);
            pre.executeUpdate();
            response.sendRedirect("AddInform.jsp");
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
